package com.Cost.service;

import com.Cost.entity.Cost;
import io.github.resilience4j.circuitbreaker.annotation.CircuitBreaker;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 收费信息 业务逻辑接口
 */
@Service
public interface CostService {

    /**
     * 添加收费信息
     * @param cost
     * @return
     */
    @CircuitBreaker(name = "costService", fallbackMethod = "addCostFallback")
    boolean doAddCostInfo(Cost cost);

    /**
     * 修改收费信息
     * @param cost
     * @return
     */
    @CircuitBreaker(name = "costService", fallbackMethod = "modifyCostFallback")
    boolean doModifyCostInfo(Cost cost);

    /**
     * 删除收费信息
     * @param cost
     * @return
     */
    @CircuitBreaker(name = "costService", fallbackMethod = "deleteCostFallback")
    boolean doDeleteCostInfo(Cost cost);

    /**
     * 获取收费信息
     * @param cost
     * @return
     */
    @CircuitBreaker(name = "costService", fallbackMethod = "getCostInfoFallback")
    Cost doGetCostInfo(Cost cost);

    /**
     * 获取收费列表
     * @return
     */
    @CircuitBreaker(name = "costService", fallbackMethod = "getCostInfoListFallback")
    List<Cost> doGetCostInfoList();

    /**
     * 统计收费列表
     * @return
     */
    @CircuitBreaker(name = "costService", fallbackMethod = "getStatisCostInfoListFallback")
    List<Cost> doGetStatisCostInfoList();

    /**
     * 查询收费列表
     * @param cost
     * @return
     */
    @CircuitBreaker(name = "costService", fallbackMethod = "queryCostInfoListFallback")
    List<Cost> doQueryCostInfoList(Cost cost);

    // 定义 fallback 方法（添加详细日志）
    default boolean addCostFallback(Cost cost, Throwable t) {
        // 打印错误信息
        System.err.println("【Service熔断】添加收费信息降级：" + t.getClass().getName() + " - " + t.getMessage());
        // 返回 false
        return false;
    }

    default boolean modifyCostFallback(Cost cost, Throwable t) {
        System.err.println("【Service熔断】修改收费信息降级：" + t.getClass().getName() + " - " + t.getMessage());
        return false;
    }

    default boolean deleteCostFallback(Cost cost, Throwable t) {
        System.err.println("【Service熔断】删除收费信息降级：" + t.getClass().getName() + " - " + t.getMessage());
        return false;
    }

    default Cost getCostInfoFallback(Cost cost, Throwable t) {
        System.err.println("【Service熔断】获取收费信息降级：" + t.getClass().getName() + " - " + t.getMessage());
        return null;
    }

    default List<Cost> getCostInfoListFallback(Throwable t) {
        System.err.println("【Service熔断】获取收费列表降级：" + t.getClass().getName() + " - " + t.getMessage());
        return null;
    }

    default List<Cost> getStatisCostInfoListFallback(Throwable t) {
        System.err.println("【Service熔断】统计收费列表降级：" + t.getClass().getName() + " - " + t.getMessage());
        return null;
    }

    default List<Cost> queryCostInfoListFallback(Cost cost, Throwable t) {
        System.err.println("【Service熔断】查询收费列表降级：" + t.getClass().getName() + " - " + t.getMessage());
        return null;
    }
}